<template>
	<view class="container">
		<image :src="baseurl+'project/bg4.png'" class="bg"></image>
		<view class="content">
			<!-- <pyh-nv :config="config">
				<slot>
					<view class="titleNav">预约看房</view>
				</slot>
			</pyh-nv> -->
			<view class="scrollBox">
				<view class="sexBox">
					<view class="left" @click="selectSex(1)">
						<image :src="sexIndex==1?baseurl+'project/icon8.png':baseurl+'project/icon9.png'"
							class="icon"></image>
					</view>
					<view class="right" @click="selectSex(2)">
						<image :src="sexIndex==2?baseurl+'project/icon8.png':baseurl+'project/icon9.png'"
							class="icon"></image>
					</view>
				</view>
				<view class="nameBox">
					<input type="text" class="name" v-model="name" placeholder="请输入姓名" />
				</view>
				<view class="telBox">
					<input type="text" class="tel" v-model="tel" maxlength="11" placeholder="请输入手机号" />
					<!-- <view class="shouquan" @click="getPhoneNumber">
						<view class="text">微信授权手机号</view>
					</view> -->
				</view>
				<view class="dateBox">
					<uni-datetime-picker type="date" class="datePicker" :start="start_time" :end="end_time"
						:clear-icon="false" v-model="orderDate" @change="changeDate"
						placeholder="请选择日期"></uni-datetime-picker>
				</view>
				<view class="timeBox">
					<uni-data-select :clear="false" v-model="orderTime" :localdata="orderTimeArray" @change="changeTime"
						placeholder="请选择时间"></uni-data-select>
				</view>
				<view class="renshuBox">
					<input type="tel" class="num" v-model="num" maxlength="2" placeholder="请填写随行人数" />
					<!-- <uni-data-select :clear="false" v-model="num" :localdata="numArray" @change="changeNum"
						placeholder="请选择随行人数"></uni-data-select> -->
				</view>
				<view class="submit" @click="submit">
					提交
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseurl: this.$baseurl,
				config: {
					title: '预约看房',
					bgColor: 'transparent',
					color: '#000000',
					type: 'slot'
				},
				imgUrl: this.$imgUrl,
				start_time: '',
				end_time: '',
				sexIndex: 0,
				name: '',
				tel: '',
				carNum: '',
				orderDate: '',
				orderTime: '',
				orderTimeIndex: '',
				orderTimeArray: [{
						value: 0,
						text: "9:00-10:00"
					},
					{
						value: 1,
						text: "10:00-11:00"
					},
					{
						value: 2,
						text: "11:00-12:00"
					},
					{
						value: 3,
						text: "13:00-14:00"
					},
					{
						value: 4,
						text: "14:00-15:00"
					},
					{
						value: 5,
						text: "15:00-16:00"
					},
					{
						value: 6,
						text: "16:00-17:00"
					}, {
						value: 7,
						text: "17:00-18:00"
					}
				],
				id: '',
				num: '',
				numIndex: '',
				numArray: [{
						value: 0,
						text: "1"
					},
					{
						value: 1,
						text: "2"
					},
					{
						value: 2,
						text: "3"
					},
					{
						value: 3,
						text: "4"
					},
					{
						value: 4,
						text: "5"
					},
					{
						value: 5,
						text: "6"
					},
					{
						value: 6,
						text: "7"
					},
					{
						value: 7,
						text: "8"
					},
					{
						value: 8,
						text: "9"
					},
					{
						value: 9,
						text: "10"
					}
				],
				user_id: ''
			}
		},
		onLoad(options) {
			this.id = options.id;
		},
		methods: {
			getPhoneNumber() {
				this.tel = uni.getStorageSync('phone');
			},
			changeTime(e) {
				// console.log(e);
				this.orderTimeIndex = e;
				// console.log(this.orderTimeArray[e].text)
				// this.orderTime = this.orderTimeArray[e].text;
			},
			changeDate(e) {
				console.log('选择的日期为:', e);
				this.orderDate = e;
			},
			selectSex(num) {
				this.sexIndex = num;
			},
			changeNum(e) {
				console.log(e);
				this.numIndex = e;
			},
			submit() {
				if (this.sexIndex == 0) {
					this.$u.toast('请选择性别')
					return;
				}
				if (this.name == '') {
					this.$u.toast('请填写姓名')
					return;
				}
				if (this.tel == '') {
					this.$u.toast('请填写手机号码')
					return;
				}
				if (this.orderDate == '') {
					this.$u.toast('请选择日期')
					return;
				}
				if (this.orderTimeIndex === '') {
					this.$u.toast('请选择时间')
					return;
				}
				// 预约
				this.$request.post(`ProjectSubscribe/user_sub`, {
					project_id: this.id,
					sex: this.sexIndex,
					name: this.name,
					phone: this.tel,
					subscribe_date: this.orderDate,
					subscribe_time: this.orderTimeArray[this.orderTimeIndex].text,
					num: this.num,
				}).then(res => {
					console.log(res);
					if (res.data.code > 0) { //预约成功
						this.$navto.navto('../oder_result/oder_result', {
							id: 1
						})
					} else {
						this.$navto.navto('../oder_result/oder_result', {
							id: 2
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.submit {
		width: 500rpx;
		height: 90rpx;
		border-radius: 10rpx;
		margin-left: 125rpx;
		margin-top: 100rpx;
		font-size: 28rpx;
		text-align: center;
		color: #FAFAFA;
		line-height: 90rpx;
		background-color: #4E97AD;
	}

	.nameBox {
		width: 674rpx;
		height: 88rpx;
		margin-top: 43rpx;
		margin-left: 39rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;

		.name {
			width: 100%;
			height: 100%;
			margin-left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
		}
	}

	.telBox {
		// width: 427rpx;
		width: 674rpx;
		height: 88rpx;
		margin-top: 25rpx;
		margin-left: 37rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		position: relative;
		background-color: #fff;

		.tel {
			position: absolute;
			width: 100%;
			height: 100%;
			left: 10rpx;
			border: none;
			text-align: left;
			font-size: 26rpx;
			color: #000000;
		}

		.shouquan {
			position: absolute;
			width: 210rpx;
			height: 95%;
			top: 0;
			left: 463rpx;
			background: #4E97AD;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			.text {
				text-align: center;
				width: 162rpx;
				height: 70rpx;
				line-height: 70rpx;
				font-size: 22rpx;
				color: #ffffff;
			}
		}
	}



	.dateBox {
		width: 590rpx;
		height: 82rpx;
		margin-left: 117rpx;
		border-radius: 10rpx;
		margin-top: 120rpx;

		.uni-date-x--border {
			border: none;
		}

		.uni-date-x {
			background-color: #ffffff !important;
		}

		.icon-calendar {
			display: none;
		}

		.uni-date,
		.uni-date-editor {
			width: 100%;
			// height: 90rpx !important;
			padding-top: 4rpx;
		}

		.uni-date__x-input {
			color: #000;
			font-size: 26rpx !important;
		}

		::deep .uni-date-x--border {
			border: none !important;
		}

		.uni-date-x {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			border-radius: 4px;
			background-color: transparent;
			color: #666;
			font-size: 14px;
			flex: 1;
			// height: 90rpx;
		}

		.uni-date__x-input {
			text-align: left;
		}
	}

	.timeBox,
	.renshuBox {
		width: 590rpx;
		height: 82rpx;
		margin-left: 117rpx;
		margin-top: 124rpx;
		// padding-left: 60rpx;
		// background-color: #ffffff !important;
		border-radius: 10rpx;
		padding-top: 6rpx;
		.num{
			width: 100%;
			height: 100%;
			background-color: #fff;
		}
		.renshu {
			margin-left: 35rpx;
			width: 100%;
			height: 100%;
			font-size: 22rpx;
			text-align: left;
			color: #fff;
		}

		.uni-stat__select {
			height: 100% !important;
			width: 96%;
		}

		.uni-select {
			padding: 0;
			padding-left: 0;
			border: none !important;
		}

		.uni-select__input-placeholder {
			color: #fff;
			text-align: left;

		}

		.uni-icons {
			display: none;
		}

		.uni-select__input-text {
			color: #000 !important;
			text-align: left;
		}
	}


	.menuBox {
		position: absolute;
		width: 670rpx;
		height: 90rpx;
		background-color: #C49A69;
		margin-top: 1330rpx;
		left: 40rpx;

		.menuText {
			width: 100%;
			height: 100%;
			line-height: 90rpx;
			text-align: center;
			font-size: 30rpx;
			color: #ffffff;
		}
	}

	.sexBox {
		// width: 690rpx;
		height: 25rpx;
		margin-top: 215rpx;
		margin-left: 40rpx;
		display: flex;
		align-items: center;

		.left {
			display: flex;
			align-items: center;

			.icon {
				width: 25rpx;
				height: 25rpx;
				margin-top: 2rpx;
			}

			.text {
				font-size: 24rpx;
				color: #000000;
				margin-left: 30rpx;
				line-height: 24rpx;
			}
		}

		.right {
			display: flex;
			align-items: center;
			margin-left: 160rpx;

			.icon {
				width: 25rpx;
				height: 25rpx;
				margin-top: 2rpx;
			}

			.text {
				font-size: 24rpx;
				color: #000000;
				margin-left: 30rpx;
				line-height: 24rpx;
			}
		}

		.active {
			color: #51B18B !important;
		}
	}

	.scrollBox {
		position: fixed;
		width: 100%;
		height: 100vh;
		overflow-y: scroll;
	}

	.container {
		position: fixed;
		width: 100%;
		height: 100vh;
		overflow-y: hidden;
		background-color: #F5F7FB;
	}

	.bg {
		position: absolute;
		width: 750rpx;
		height: 1473rpx;
		left: 0;
		top: 0;
	}

	.titleNav {
		text-align: center;
		font-weight: 700;
		font-size: 34rpx;
		color: #3E3A39;
		margin-left: 54%;
	}

	.content {
		position: fixed;
		width: 100%;
		height: 100vh;
		overflow-y: hidden;
	}
</style>